/**
 * @file    Expression classname is undefined on line 2, column 15 in Templates/Classes/Class.java.
 * @author  Haseeb Yousaf
 * @see     LICENSE (MIT style license file)
 * @version 1.0
 * @date    Nov 17, 2011 4:42:15 PM
 */
package carrello.impl.boundary.administrator;

import carrello.impl.boundary.AbstractUI;
import carrello.impl.controller.administrator.DeleteCategoryCTRL;
import carrello.model.entities.*;
import carrello.model.entitydao.CategoryDAO;
import java.util.List;
import static carrello.util.EntityManagerUtil.getEntityManager;


public class DeleteCategoryUI extends AbstractUI{
    private List<Category> categories;
    private int cid;
    private List<Category> catList; 
    
    public String execute()
    {
        if ( !getSessionIsLoggedIn()) {
            return LOGIN;
        } // if
        if (cid == 0)
        {
            return ERROR;
        } else {
            deleteCategory(cid);
            getEntityManager().getHibernateSession().clear();
        } // end if
        return "browse";
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }

    public int getCid() {
        return cid;
    }

    public void setCid(int cid) {
        this.cid = cid;
    }
    
    public void deleteCategory(int cid)
    {
        DeleteCategoryCTRL delCat = new DeleteCategoryCTRL();
        delCat.delete(cid);
    }
    
    public List<Category> getCatList() {
        return new CategoryDAO().getAll();
    }

    public void setCatList(List<Category> catList) {
        this.catList = catList;
    }
}
